package com.wen.controller.biz;

import com.wen.business.service.ProductService;
import com.wen.common.pojo.account.Product;
import com.wen.common.vo.DataVO;
import com.wen.common.vo.ProductVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class ProductController {

    @Autowired
    private ProductService productService;


/*
    使用下面的分页
    @RequestMapping("/list")
    public List<Product> list() {
        return productService.findAll();
    }
*/

    @RequestMapping("/list") // @RequestParam 将指定的请求参数赋值给方法中的形参。
    public List<Product> list(@RequestParam(name = "page", defaultValue = "1") int current,
                              @RequestParam(name = "limit", defaultValue = "5") int pageSize) {

        System.out.println("======================" + current + pageSize);
        return productService.findAllPage(current, pageSize);
    }

    @RequestMapping("/listVo")
    public DataVO<ProductVO> listVo() {
        return productService.findDate();
    }

    @GetMapping("/page/{page}/{pageSize}")// @PathVariable 接收请求路径中占位符的值。用于get请求
    public List<Product> page(@PathVariable("page") int current,
                              @PathVariable("pageSize") int pageSize) {
        System.out.println("======================" + current + pageSize);
        return productService.findAllPage(current, pageSize);
    }


}
